package com.xiaolin.service;

import com.xiaolin.dao.FriendsMapper;
import com.xiaolin.pojo.Friends;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author XiaoLin
 * @date 2019/2/25 08:04
 */
@Service
public class FriendService {

    @Autowired
    private FriendsMapper friendsMapper;


    /**
     * 通过用户Id获取该用户好友信息
     *
     * @param userId
     * @return
     */
    public List<Friends> findFriendByMyId(String userId) {
        return friendsMapper.findFriendByMyId(userId);
    }

    /**
     * 判断是否已经存在申请记录
     *
     * @param userId
     * @param uid
     * @return
     */
    public boolean findIsFriend(String userId, String uid) {
        Example example = new Example(Friends.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("myUid", userId);
        criteria.andEqualTo("myFriendUid", uid);
        List<Friends> friends = friendsMapper.selectByExample(example);
        if (friends.size() >= 1) {
            return true;
        }
        return false;
    }

    public void insert(Friends f) {
        friendsMapper.insert(f);
    }
}
